﻿using System.ComponentModel;
using System.Runtime.Serialization;
using TpBaseObjects.Base;

namespace TpBaseObjects.Models {

    public class CashSaleDetailsModel : MyBaseModel {

        #region Members

        private int detailsID = 0;
        private byte taxCode = 0;
        private int productID = 0;
        private double quantity = 0;
        private double price;
        private double rabattPercent1;
        private double rabattPercent2;
        private double rabattFix;
        private string unity;

        #endregion

        #region Constructor

        public CashSaleDetailsModel() {
        }

        #endregion

        #region Properties

        [DataMember]
        public int DetailsID {
            get { return this.detailsID; }
            set { this.detailsID = value; }
        }

        [DataMember]
        public int CashSaleID {
            get;
            set;
        }

        [DataMember]
        public bool IsChecked {
            get;
            set;
        }

        [DataMember]
        public int ProductID {
            get { return this.productID; }
            set {
                if (this.productID == value) {
                    return;
                }
                this.productID = value;
                OnPropertyChanged(() => ProductID);
            }
        }

        [DataMember]
        public string ProductName {
            get;
            set;
        }

        [DataMember]
        public double Quantity {
            get { return this.quantity; }
            set {
                if (this.quantity == value) {
                    return;
                }
                this.quantity = value;
                OnPropertyChanged(() => Quantity);
            }
        }

        [DataMember]
        public double Price {
            get { return this.price; }
            set {
                if (this.price == value) {
                    return;
                }
                this.price = value;
                OnPropertyChanged(() => Price);
            }
        }

        [DataMember]
        public double RabattPercent1 {
            get { return this.rabattPercent1; }
            set {
                if (this.rabattPercent1 == value) {
                    return;
                }
                this.rabattPercent1 = value;
                OnPropertyChanged(() => RabattPercent1);
            }
        }

        public double RabattPercent2 {
            get { return this.rabattPercent2; }
            set {
                if (this.rabattPercent2 == value) {
                    return;
                }
                this.rabattPercent2 = value;
                OnPropertyChanged(() => RabattPercent2);
            }
        }

        [DataMember]
        public double RabattFix {
            get { return this.rabattFix; }
            set {
                if (this.rabattFix == value) {
                    return;
                }
                this.rabattFix = value;
                OnPropertyChanged(() => RabattFix);
            }
        }

        public double SalePrice {
            get {
                return (this.Price * this.Quantity) * (1 - (this.RabattPercent1 / 100)) * (1 - (this.RabattPercent2 / 100)) - this.RabattFix;
            }
        }

        [DataMember]
        public byte TaxCode {
            get { return this.taxCode; }
            set {
                if (this.taxCode == value) {
                    return;
                }
                this.taxCode = value; 
                OnPropertyChanged(()=> TaxCode);
            }
        }

        public double TaxRate {
            get;
            set;
        }

        [DataMember]
        public string Unity {
            get { return this.unity; }
            set {
                if (this.unity == value) {
                    return;
                }
                this.unity = value;
                OnPropertyChanged(() => Unity);
            }
        }

        #endregion

    }
}
